/*
 */
package gclib;

import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;

/**Abilities.java
 * This is a complete bundle of the six abilities that any toon has.
 * Created Jul 22, 2009 10:46:41 PM
 * @author Jason
 */
public class Abilities {

    /** The six types of abilities. */
    public static enum TYPE {

        STR, CON, DEX, INT, WIS, CHA
    };
    private Map<TYPE, Ability> abil = new EnumMap<TYPE, Ability>(TYPE.class);

    public Abilities() {
        for (TYPE type : Abilities.TYPE.values()) {
            abil.put(type, new Ability());
        }
    }

	public Abilities(int STR, int CON, int DEX, int INT, int WIS, int CHA) {
		abil.put(TYPE.STR, new Ability(STR));
		abil.put(TYPE.CON, new Ability(CON));
		abil.put(TYPE.DEX, new Ability(DEX));
		abil.put(TYPE.INT, new Ability(INT));
		abil.put(TYPE.WIS, new Ability(WIS));
		abil.put(TYPE.CHA, new Ability(CHA));
	}

	public Ability getAbility(TYPE type) {
		return abil.get(type);
	}

    public int getScore(TYPE type) {
        return abil.get(type).score + abil.get(type).misc + abil.get(type).raceBonusValue;//((abil.get(type).classBonus) ? 2 : 0);
    }

    public int getModifier(TYPE type) {
        return getScore(type) / 2 - 5;
    }

    public void setScore(TYPE type, Integer value) {
        abil.get(type).score = (value > -1) ? value : 0;
    }

	public void setRaceBonuses(Race race) {
        for (Ability ability : abil.values()) {
            ability.raceBonus = false;
        }
        for (Entry<TYPE, Integer> entries : race.abilityBonusMap.entrySet()) {
            abil.get(entries.getKey()).raceBonus = true;
			abil.get(entries.getKey()).raceBonusValue = entries.getValue();
        }
	}

    public void setClassBonuses(Class clazz) {
        for (Ability ability : abil.values()) {
            ability.classKeyAbility = false;
        }
        for (Abilities.TYPE entry : clazz.getKeyAbilities()) {
            abil.get(entry).classKeyAbility = true;
//			abil.get(entry.getKey()).classBonusValue = entry.getValue();
        }
    }

    public void setMisc(TYPE type, Integer value){
        abil.get(type).misc = value;
    }

    @Override
    public String toString() {
        String rtv = "";
        for (Map.Entry<TYPE, Ability> entry : abil.entrySet()) {
            rtv += "\t" + entry.getKey() + ":" + getScore(entry.getKey()) + " > " + getModifier(entry.getKey()) + "\n";
        }
        return this.getClass().getSimpleName() + "[\n" + rtv + "]";
    }

    protected class Ability {

        private int score = 0;
        private int misc = 0;
		private int raceBonusValue = 0;
        private boolean classKeyAbility = false;
		private boolean raceBonus = false;

		Ability() {
		}

		Ability(int score) {
			this.score = score;
		}

		public boolean isClassKeAbility() {
			return classKeyAbility;
		}

		public void setClassKeyAbility(boolean classKeyAbility) {
			this.classKeyAbility = classKeyAbility;
		}

		public int getMisc() {
			return misc;
		}

		public void setMisc(int misc) {
			this.misc = misc;
		}

		public boolean isRaceBonus() {
			return raceBonus;
		}

		public void setRaceBonus(boolean raceBonus) {
			this.raceBonus = raceBonus;
		}

		public int getRaceBonusValue() {
			return raceBonusValue;
		}

		public void setRaceBonusValue(int raceBonusValue) {
			this.raceBonusValue = raceBonusValue;
		}

		public int getScore() {
			return score;
		}

		public void setScore(int score) {
			this.score = score;
		}
		
    }
}
